<template>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="1200px" append-to-body>
        <div>
            <div class="order-header">
                <div class="header-title">
                    <span class="header-title-title">{{ model.name }}</span>
                    <el-tag type="info">{{ model.financial_status }}</el-tag>
                    <el-tag type="info" v-if="model.fulfillment_status">{{ model.fulfillment_status }}</el-tag>
                    <el-tag type="info"><el-link type="primary" @click="JumpToShopify()">跳转到shopify</el-link></el-tag>
                </div>
                <div class="header-tip">{{ model.created_at }} from {{ model.currency }}</div>
                <div class="header-tip">转单号：{{ model.tracking_number_new }}</div>
            </div>
            <div class="order-content">
                <div class="order-main">
                    <div class="order-card">
                        <div class="card-header">
                            <el-tag type="primary">商品明细</el-tag>
                        </div>
                        <div class="card-content">
                            <!-- <div class="card-item">
                                <div>Delivery method</div>
                                <div class="text-bold">Standard</div>
                            </div> -->
                            <div class="card-item" v-for="(iteminfo, indexinfo) in model.order_info" :key="indexinfo" >
                                <!-- <div class="card-item-logo">
                                    <el-image></el-image>
                                </div> -->
                                <div class="card-item-content">
                                    <div>{{ iteminfo.name }}</div>
                                </div>
                                <div class="card-item-right">
                                    <div>{{ iteminfo.sku }} x {{ iteminfo.quantity }}件</div>
                                </div>
                                <div class="card-item-right">
                                    <div>{{ iteminfo.price }}{{ model.currency }}</div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="order-card">
                        <div class="card-header">
                            <el-tag type="primary">物流轨迹</el-tag>
                        </div>
                        <div class="card-content" v-for="(iteminfo, indexinfo) in model.order_fulfillments" :key="indexinfo" >
                            <div class="card-item">
                                <div class="card-item-left text-bold">物流商：{{ iteminfo.provider_name }}</div>
                                <div class="card-item-content">物流单号：{{ iteminfo.track_number }}</div>
                                <div class="card-item-content">最新状态：{{ iteminfo.latest_status }}</div>
                                <div class="card-item-right">
                                    <div class="">时间：{{ iteminfo.create_time }}</div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="order-card">
                        <div class="card-header">
                            <el-tag type="primary">交易记录</el-tag>
                        </div>
                        <div class="card-content" v-for="(iteminfo, indexinfo) in model.order_transactions" :key="indexinfo" >
                            <div class="card-item">
                                <div class="card-item-left text-bold">渠道：{{ iteminfo.gateway }}</div>
                                <div class="card-item-content">ID:{{ iteminfo.authorization }}</div>
                                <div class="card-item-content">时间{{ iteminfo.created_at }}</div>
                                <div class="card-item-content">状态{{ iteminfo.kind }}，{{ iteminfo.status }}</div>
                                <div class="card-item-right">
                                    <div class="">{{ iteminfo.amount }}{{ iteminfo.currency }}</div>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
                <div class="order-sub">
                    <div class="order-card">
                        <div class="text-bold" style="margin: 0 0 8px 0">店铺</div>
                        <div>{{ model.shops.name }}</div>
                        <div>{{ model.shops.domain }}</div>
                        <div>{{ model.shops.myshopify_domain }}</div>
                        <div>{{ model.shops.timezone }}</div>
                    </div>
                    <div class="order-card">
                        <div class="text-bold" style="margin: 0 0 8px 0">客户</div>
                        <div class="text-primary">邮箱：{{ model.order_customer.email }}</div>
                        <div>昵称：{{ model.order_customer.first_name }}{{ model.order_customer.last_name }}</div>
                        <div></div>
                        <div>电话：{{ model.order_customer.phone }}</div>
                        <div>创建时间：{{ model.order_customer.created_at }}</div>
                    </div>
                    <!-- <div class="order-card">
                        <div class="text-bold" style="margin: 0 0 8px 0">Shipping address</div>
                        <div class="text-primary">地址：{{ model.order_shipping.country }}{{ model.order_shipping.province }}{{ model.order_shipping.city }}</div>
                        <div>昵称：{{ model.order_shipping.name }}</div>
                        <div></div>
                        <div>电话：{{ model.order_shipping.phone }}</div>
                    </div> -->
                    <div class="order-card">
                        <div class="text-bold" style="margin: 0 0 8px 0">支付明细</div>
                        <div class="text-primary">小计：{{ model.order_achievement.subtotal_price }}{{ model.currency }}</div>
                        <div>折扣：{{ model.order_achievement.discounted_price }}{{ model.currency }}</div>
                        <div></div>
                        <div>总计：{{ model.order_achievement.total_price }}{{ model.currency }}</div>
                    </div>
                </div>
            </div>
        </div>
        <div slot="footer" class="dialog-footer"></div>
    </el-dialog>
</template>

<script>
import { queryOrderDetail } from '@/api/order'

export default {
    name: 'ProductDialog',
    props: {
        value: {
            type: Boolean,
            default: false,
            required: true,
        },
        params: {
            type: Object,
            default: () => {},
        },
        type: {
            type: String,
            default: '',
        },
    },
    data() {
        return {
            loading: false,
            model: {
                id: '',
                name: '',
                supply_name: '',
                supply_link: '',
                currency: '',
                shops: {
                    name: '',
                    domain: '',
                    myshopify_domain: '',
                    timezone: '',
                },
                order_customer: {
                    email: '',
                    first_name: '',
                    last_name: '',
                    phone: '',
                    created_at: '',
                },
                // order_shipping: {
                //     country: '',
                //     city: '',
                //     name: '',
                //     phone: '',
                // },
                order_achievement: {
                    subtotal_price: '',
                    discounted_price: '',
                    total_price: '',
                },
            },
            rules: {
                // supply_name: [{ required: true, message: '供应商名称不能为空', trigger: ['blur', 'change'] }],
            },
        }
    },
    computed: {
        title() {
            return `订单详情`
        },
        isDisabled() {
            return this.type === 'view'
        },
        dialogVisible: {
            get() {
                return this.value
            },
            set(val) {
                this.$emit('input', val)
            },
        },
    },
    watch: {
        params: {
            handler(val) {
                if (val) {
                    this.model = Object.assign({}, this.model, val)
                }
            },
            immediate: true,
            deep: true,
        },
    },
    mounted() {
        this.getDetail()
    },
    methods: {
        JumpToShopify(){
            //跳转到https://admin.shopify.com/store/vfaja/orders/6888431321458 新开页面
            window.open(`https://admin.shopify.com/store/vfaja/orders/${this.model.order_id}`)
        },
        getDetail() {
            this.loading = true
            const params = { order_id: this.params.order_id }
            queryOrderDetail(params)
                .then(res => {
                    this.model = Object.assign({}, this.model, res.data)
                })
                .finally(() => {
                    this.loading = false
                })
        },
    },
}
</script>

<style>
.order-page {
    min-height: 100%;
    background: #f1f1f1;
}
.order-header {
    margin-bottom: 24px;
    padding-left: 24px;
}
.header-title-title {
    font-size: 18px;
    line-height: 32px;
    font-weight: bold;
    margin-right: 8px;
}
.order-content {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
}
.order-main {
    width: 66%;
    margin-right: 2%;
}
.order-sub {
    width: 32%;
}
.order-card {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: 0 0 4px #eee;
}
.card-content {
    margin: 8px 0;
    border: 1px solid #f5f5f5;
    border-radius: 8px;
}
.card-item {
    padding: 16px;
    border-bottom: 1px solid #f5f5f5;
    display: flex;
    flex-wrap: nowrap;
}
.card-item:last-child {
    border-bottom: 0;
}
.card-item-logo {
    width: 50px;
    height: 50px;
    border: 1px solid #f5f5f5;
    border-radius: 4px;
    margin-right: 16px;
}
.card-item-logo .el-image {
    width: 50px;
    height: 50px;
}
.card-item-content {
    flex: 1;
}
.card-item-left,
.card-item-right {
    width: 15%;
}
.card-item-right {
    text-align: right;
}
.text-bold {
    font-weight: bold;
}
.text-primary {
    color: #11a983;
}
</style>
